/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ImagePostPanel.java
 *
 * Created on 22/Out/2012, 10:48:15
 */
package chatclient;

import com.sd.chat.Post;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import org.jdesktop.application.Action;

/**
 *
 * @author Old
 */
public class ImagePostPanel extends javax.swing.JPanel {

    private Post estePost;
    private ChatSDClientView pai;

    /** Creates new form ImagePostPanel */
    public ImagePostPanel(ChatSDClientView pai, Post post, boolean isMine) {
        initComponents();
        this.pai = pai;
        estePost = post;
        posterName.setText(post.getUser().getNome());
        postText.setText(post.getText());
        ImageIcon icoPic = new ImageIcon(post.getPic());
        JLabel jLabel2 = new JLabel(icoPic);
        jLabel2.setSize(465, 270);
        picPanel.add(jLabel2);
        if (!isMine) {
            butEdit.setVisible(isMine);
            butEliminar.setVisible(isMine);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        posterName = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        postText = new javax.swing.JTextArea();
        picPanel = new javax.swing.JPanel();
        butEdit = new javax.swing.JButton();
        butComment = new javax.swing.JButton();
        butEliminar = new javax.swing.JButton();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(chatclient.ChatSDClientApp.class).getContext().getResourceMap(ImagePostPanel.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        setMaximumSize(new java.awt.Dimension(650, 32767));
        setMinimumSize(new java.awt.Dimension(650, 230));
        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(650, 230));

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        posterName.setText(resourceMap.getString("posterName.text")); // NOI18N
        posterName.setName("posterName"); // NOI18N

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane1.setFocusable(false);
        jScrollPane1.setMaximumSize(new java.awt.Dimension(595, 32767));
        jScrollPane1.setName("jScrollPane1"); // NOI18N
        jScrollPane1.setPreferredSize(new java.awt.Dimension(595, 96));

        postText.setBackground(resourceMap.getColor("postText.background")); // NOI18N
        postText.setColumns(20);
        postText.setRows(5);
        postText.setName("postText"); // NOI18N
        jScrollPane1.setViewportView(postText);

        picPanel.setBackground(resourceMap.getColor("picPanel.background")); // NOI18N
        picPanel.setMaximumSize(new java.awt.Dimension(300, 200));
        picPanel.setMinimumSize(new java.awt.Dimension(300, 200));
        picPanel.setName("picPanel"); // NOI18N
        picPanel.setPreferredSize(new java.awt.Dimension(300, 200));

        javax.swing.GroupLayout picPanelLayout = new javax.swing.GroupLayout(picPanel);
        picPanel.setLayout(picPanelLayout);
        picPanelLayout.setHorizontalGroup(
            picPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
        picPanelLayout.setVerticalGroup(
            picPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 206, Short.MAX_VALUE)
        );

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(chatclient.ChatSDClientApp.class).getContext().getActionMap(ImagePostPanel.class, this);
        butEdit.setAction(actionMap.get("clickedEditPost")); // NOI18N
        butEdit.setText(resourceMap.getString("butEdit.text")); // NOI18N
        butEdit.setName("butEdit"); // NOI18N

        butComment.setAction(actionMap.get("clickedCommentPost")); // NOI18N
        butComment.setText(resourceMap.getString("butComment.text")); // NOI18N
        butComment.setName("butComment"); // NOI18N

        butEliminar.setAction(actionMap.get("clickedEliminarPost")); // NOI18N
        butEliminar.setText(resourceMap.getString("butEliminar.text")); // NOI18N
        butEliminar.setName("butEliminar"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(posterName))
                    .addComponent(butEdit)
                    .addComponent(butComment)
                    .addComponent(butEliminar))
                .addGap(6, 6, 6)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(picPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(191, 191, 191))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(picPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(posterName))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(butEdit)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(butComment)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(butEliminar)))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void clickedCommentPost() {
        pai.setNewCommentToolPanel(estePost.getId());
    }

    @Action
    public void clickedEditPost() {
        pai.setEditPostToolPanel(estePost);
    }

    @Action
    public void clickedEliminarPost() {
        Object[] options = {"Sim",
            "Não"};
        int n = JOptionPane.showOptionDialog(this,
                "Este Post e todos os seus comentários serão eliminados, dejesa continuar?",
                "Eliminar",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.WARNING_MESSAGE,
                null, //do not use a custom Icon
                options, //the titles of buttons
                options[0]); //default button title
        if (n == 0) {
            pai.eliminateSubmit(estePost.getId(), true);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton butComment;
    private javax.swing.JButton butEdit;
    private javax.swing.JButton butEliminar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel picPanel;
    private javax.swing.JTextArea postText;
    private javax.swing.JLabel posterName;
    // End of variables declaration//GEN-END:variables
}
